<template>
  <lab-process v-if="element.props.callCmd && appInfo.appId" :element="element" :model-data="modelData" />
  <el-empty v-else description="未知视图" style="height: 100%"></el-empty>
</template>

<script>
import LabProcess from "@/components/lab-process/LabProcess";
export default {
  name: "ModelView",
  components: {LabProcess},
  provide() {
    return {
      appInfo: this.appInfo
    }
  },
  data () {
    return {
      element: { elements: [], props: { callCmd: '' } },
      modelData: {},
      appInfo: { appId: '' }
    }
  },
  created() {
    this.initView()
  },
  methods: {
    initView(){
      const { query, params, path } = this.$route
      this.$Util.copyAttr(params, this.modelData,null, this)
      this.$Util.copyAttr(query, this.modelData,null, this)
      let { callCmd } = this.modelData
      if (!callCmd) {
        const paths = path.split('/')
        callCmd = paths[paths.length - 1]
      }
      if (callCmd) {
        this.$set(this.element.props, 'callCmd', callCmd)
      }
      this.loadApp()
    },
    loadApp() {
      const { appId } = this.modelData
      if (!appId) {
        this.appInfo.appId = '0'
        return
      }
      this.$get('/appInfo/get/' + appId)
          .then(res => {
            this.$resultMsg(this, res, '应用加载异常', true)
            this.$Util.cleanObj(this, this.appInfo)
            if (res.code === 200) {
              this.$Util.copyAttr(res.data, this.appInfo, null, this)
            }
          })
    }
  }
}
</script>

<style scoped>

</style>
